<?php
class JiaodianAction extends Action {
    /**
     * 首页焦点图
     * @author 沈威
     * @tel 15005164276
     * @email 403382132@qq.com
     * Enter description here ...
     */
	public function shouye()
	{
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		
		$this->display();
	}
	
	/**
     * 图片焦点图
     * @author 沈威
     * @tel 15005164276
     * @email 403382132@qq.com
     * Enter description here ...
     */
	public function picture()
	{
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		
		$this->display();
	}
	
	/**
     * 首页焦点图提交
     * @author 沈威
     * @tel 15005164276
     * @email 403382132@qq.com
     * Enter description here ...
     */
	public function doshouye()
	{
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		$jiaodianmodel=M('Jiaodian');
		if (!empty($_FILES)) {
	        $files1['0'] = $_FILES['tupian1'];
	        $files2['0'] = $_FILES['tupian2'];
	        $files3['0'] = $_FILES['tupian3'];
	        $files4['0'] = $_FILES['tupian4'];
	        $files5['0'] = $_FILES['tupian5'];
	        $data1['id']=1;
	        if($files1['0']['name']){
	        	$uploadList = uploadsource('-1','bmp,jpg,gif,png,jpeg','./Public/Admin/Jiaodian/',$files1);
	        	if(is_array($uploadList)){
		        	$data1['image']=$uploadList[0]['savename'];
	        	}else{
		        	$this->error($uploadList);
		        }
	        }
	        if($_POST['lianjie1']){
	        	$data1['lianjie']=$_POST['lianjie1'];
	        }
	        if($_POST['lianjie1'] || $files1['0']['name']){
	        	$r1 = $jiaodianmodel->save($data1);
	        }
	       
	        
	        $data2['id']=2;
			if($files2['0']['name']){
	        	$uploadList = uploadsource('-1','bmp,jpg,gif,png,jpeg','./Public/Admin/Jiaodian/',$files2);
	        	if(is_array($uploadList)){
		        	$data2['image']=$uploadList[0]['savename'];
	        	}else{
		        	$this->error($uploadList);
		        }
	        }
			if($_POST['lianjie2']){
	        	$data2['lianjie']=$_POST['lianjie2'];
	        }
	        if($_POST['lianjie2'] || $files2['0']['name']){
	        	$r2 = $jiaodianmodel->save($data2);
	        }
	        
	        $data3['id']=3;
			if($files3['0']['name']){
	        	$uploadList = uploadsource('-1','bmp,jpg,gif,png,jpeg','./Public/Admin/Jiaodian/',$files3);
	        	if(is_array($uploadList)){
		        	$data3['image']=$uploadList[0]['savename'];  	
	        	}else{
		        	$this->error($uploadList);
		        }
	        }
			if($_POST['lianjie3']){
	        	$data3['lianjie']=$_POST['lianjie3'];
	        }
	        if($_POST['lianjie3'] || $files3['0']['name']){
	        	$r3 = $jiaodianmodel->save($data3);
	        }
	        
	        $data4['id']=4;
			if($files4['0']['name']){
	        	$uploadList = uploadsource('-1','bmp,jpg,gif,png,jpeg','./Public/Admin/Jiaodian/',$files4);
	        	if(is_array($uploadList)){
		        	$data4['image']=$uploadList[0]['savename'];
	        	}else{
		        	$this->error($uploadList);
		        }
	        }
			if($_POST['lianjie4']){
	        	$data4['lianjie']=$_POST['lianjie4'];
	        }
	        if($_POST['lianjie4'] || $files4['0']['name']){
	        	$r4 = $jiaodianmodel->save($data4);
	        }
	        
	        $data5['id']=5;
			if($files5['0']['name']){
	        	$uploadList = uploadsource('-1','bmp,jpg,gif,png,jpeg','./Public/Admin/Jiaodian/',$files5);
	        	if(is_array($uploadList)){
		        	$data5['image']=$uploadList[0]['savename'];
	        	}else{
		        	$this->error($uploadList);
		        }
	        }
			if($_POST['lianjie5']){
	        	$data5['lianjie']=$_POST['lianjie5'];
	        }
	        if($_POST['lianjie5'] || $files5['0']['name']){
	        	$r5 = $jiaodianmodel->save($data5);
	        }
		    	/*$uploadList = uploadsource('-1','bmp,jpg,gif,png,jpeg','./Public/Admin/Jiaodian/',$files);
				if(is_array($uploadList)){
			    	import("ORG.Util.Image");
			        //给m_缩略图添加水印, Image::water('原文件名','水印图片地址')
			        $num = count($uploadList);
			        $str = "";
			        for ( $i=0; $i<$num; $i++){
			        	$info = Image::getImageInfo($uploadList[$i]['savepath'] . $uploadList[$i]['savename']);
				        Image::water($uploadList[$i]['savepath'] . 'm_' . $uploadList[$i]['savename'], './Public/Images/logo.jpg', $uploadList[$i]['savepath'] .'sy_' . $uploadList[$i]['savename'], 20);
				        $m = $i+1;
				        if($m<$num){
				        	$str .= $uploadList[$i]['savename'].",";
						        }else{
						        	$str .= $uploadList[$i]['savename'];
						        }
					        }
					        $_POST['url'] = $str;
				        }else{
				        	 $this->error($uploadList);
				        }
				         
			        }else{
			        	 $this->error("修改失败!");
			        }
					$image=explode(',', $_POST['url']);
					$jiaodianmodel=M('Jiaodian');
			        for($i=1;$i<6;$i++)
			        {
			        	$data['id']=$i;
			        	$data['image']=$image[$i-1];
			        	$data['lianjie']=$_POST['lianjie'.$i];
			        	$jiaodianmodel->save($data);
			        }*/
				}else{
		        	 $this->error("修改失败!");
		        }
		    if($r1 || $r2 || $r3 || $r4 || $r5){
				$this->success("修改成功!");
		    }else{
		    	$this->success("无修改!");
		    }
	}
	
	/**
     * 图片焦点图提交
     * @author 沈威
     * @tel 15005164276
     * @email 403382132@qq.com
     * Enter description here ...
     */
	public function dopicture()
	{
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		$jiaodianmodel=M('Jiaodian');
		if (!empty($_FILES)) {
			$files1['0'] = $_FILES['tupian6'];
	        $files2['0'] = $_FILES['tupian7'];
	        $files3['0'] = $_FILES['tupian8'];
	        $files4['0'] = $_FILES['tupian9'];
	        $files5['0'] = $_FILES['tupian10'];
	        $data1['id']=6;
	        if($files1['0']['name']){
	        	$uploadList = uploadsource('-1','bmp,jpg,gif,png,jpeg','./Public/Admin/Jiaodian/',$files1);
	        	if(is_array($uploadList)){
		        	$data1['image']=$uploadList[0]['savename'];
	        	}else{
		        	$this->error($uploadList);
		        }
	        }
			if($_POST['lianjie6']){
	        	$data1['lianjie']=$_POST['lianjie6'];
	        }
	        if($_POST['lianjie6'] || $files1['0']['name']){
	        	$r1 = $jiaodianmodel->save($data1);
	        }
	        
	        $data2['id']=7;
			if($files2['0']['name']){
	        	$uploadList = uploadsource('-1','bmp,jpg,gif,png,jpeg','./Public/Admin/Jiaodian/',$files2);
	        	if(is_array($uploadList)){
		        	$data2['image']=$uploadList[0]['savename'];
	        	}else{
		        	$this->error($uploadList);
		        }
	        }
			if($_POST['lianjie7']){
	        	$data2['lianjie']=$_POST['lianjie7'];
	        }
	        if($_POST['lianjie7'] || $files2['0']['name']){
	        	$r2 = $jiaodianmodel->save($data2);
	        }
	        
	        $data3['id']=8;
			if($files3['0']['name']){
	        	$uploadList = uploadsource('-1','bmp,jpg,gif,png,jpeg','./Public/Admin/Jiaodian/',$files3);
	        	if(is_array($uploadList)){
		        	$data3['image']=$uploadList[0]['savename'];
	        	}else{
		        	$this->error($uploadList);
		        }
	        }
			if($_POST['lianjie8']){
	        	$data3['lianjie']=$_POST['lianjie8'];
	        }
	        if($_POST['lianjie8'] || $files3['0']['name']){
	        	$r3 = $jiaodianmodel->save($data3);
	        }
	        
	        $data4['id']=9;
			if($files4['0']['name']){
	        	$uploadList = uploadsource('-1','bmp,jpg,gif,png,jpeg','./Public/Admin/Jiaodian/',$files4);
	        	if(is_array($uploadList)){
		        	$data4['image']=$uploadList[0]['savename'];
	        	}else{
		        	$this->error($uploadList);
		        }
	        }
			if($_POST['lianjie9']){
	        	$data4['lianjie']=$_POST['lianjie9'];
	        }
	        if($_POST['lianjie9'] || $files4['0']['name']){
	        	$r4 = $jiaodianmodel->save($data4);
	        }
	        
	        $data5['id']=10;
			if($files5['0']['name']){
	        	$uploadList = uploadsource('-1','bmp,jpg,gif,png,jpeg','./Public/Admin/Jiaodian/',$files5);
	        	if(is_array($uploadList)){
		        	$data5['image']=$uploadList[0]['savename'];
	        	}else{
		        	$this->error($uploadList);
		        }
			}
			if($_POST['lianjie10']){
	        	$data5['lianjie']=$_POST['lianjie10'];
	        }
	        if($_POST['lianjie10'] || $files5['0']['name']){
	        	$r5 = $jiaodianmodel->save($data5);
	        }
	        /*$files = $_FILES;
	    	$uploadList = uploadsource('-1','bmp,jpg,gif,png,jpeg','./Public/Admin/Jiaodian/',$files,true,'m_,s_','460,385','140,125');
			if(is_array($uploadList)){
		    	import("ORG.Util.Image");
		        //给m_缩略图添加水印, Image::water('原文件名','水印图片地址')
		        $num = count($uploadList);
		        $str = "";
		        $size = "";
		        $area = "";
		        for ( $i=0; $i<$num; $i++){
		        	$info = Image::getImageInfo($uploadList[$i]['savepath'] . $uploadList[$i]['savename']);
			        Image::water($uploadList[$i]['savepath'] . 'm_' . $uploadList[$i]['savename'], './Public/Images/logo.jpg', $uploadList[$i]['savepath'] .'sy_' . $uploadList[$i]['savename'], 20);
			        $m = $i+1;
			        if ($info[size] < 1048576){
			        	$info[size] = ceil($info[size]/1024) . "KB";
			        }else{
			        	$info[size] = round(($info[size]/1048576),1) . "M";
			        }
			        if($m<$num){
			        	$size .= $info[size].",";
			        	$area .= $info[width] . "x" . $info[height] . ",";
			        	$str .= $uploadList[$i]['savename'].",";
			        }else{
			        	$size .= $info[size];
			        	$area .= $info[width] . "x" . $info[height];
			        	$str .= $uploadList[$i]['savename'];
			        }
		        }
		        $_POST['size'] = $size;
		        $_POST['area'] = $area;
		        $_POST['url'] = $str;
	        }else{
	        	 $this->error($uploadList);
	        }*/
	         
        }else{
        	 $this->error("修改失败!");
        }
		/*$image=explode(',', $_POST['url']);
		$jiaodianmodel=M('Jiaodian');
        for($i=6;$i<11;$i++)
        {
        	$data['id']=$i;
        	$data['image']=$image[$i-6];
        	$data['lianjie']=$_POST['lianjie'.$i];
        	$jiaodianmodel->save($data);
        }*/
		if($r1 || $r2 || $r3 || $r4 || $r5){
			$this->success("修改成功!");
	    }else{
	    	$this->success("无修改!");
	    }
	}
	
	/**
	 * 跳转到文章焦点图
	 * @author 沈威
	 * @tel 15005164276
	 * @email 403382132@qq.com
	 * Enter description here ...
	 */
	public function article()
	{
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		$this->display();
	}
	
	/**
	 * 修改文章焦点图
	 * @author 沈威 
	 * @tel 15005164276
	 * @email 403382132@qq.com
	 * Enter description here ...
	 */
	public function doarticle()
	{
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		$jiaodianmodel=M('Jiaodian');
		if (!empty($_FILES))
		{
			$files1['0'] = $_FILES['tupian11'];
			if($files1['0']['name']){
	        	$uploadList = uploadsource('-1','bmp,jpg,gif,png,jpeg','./Public/Admin/Jiaodian/',$files1);
	        	if(is_array($uploadList)){
	        		$data['id']=11;
		        	$data['image']=$uploadList[0]['savename'];
		        	$data['lianjie']=$_POST['lianjie11'];
		        	$data['biaoti']=$_POST['biaoti11'];
		        	$jiaodianmodel->save($data);
	        	}else{
		        	$this->error($uploadList);
		        }
	        }
	        else 
	        {
	        	$data['id']=11;
	        	$data['lianjie']=$_POST['lianjie11'];
		        $data['biaoti']=$_POST['biaoti11'];
		        $jiaodianmodel->save($data);
	        }
		}
		else 
		{
			 $this->error("修改失败!");
		}
		$this->success("修改成功!");
	}
}